package com.stone.design.practice;

import android.content.Context;
import android.nfc.cardemulation.HostApduService;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.ViewAssertion;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.widget.Toast;

import com.stone.design.practice.java.Student;
import com.stone.design.practice.test.TestActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Timer;
import java.util.TimerTask;

import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

    Context appContext = InstrumentationRegistry.getTargetContext();

    @Rule
    public ActivityTestRule<TestActivity> rule
            = new ActivityTestRule<>(TestActivity.class);
    @Test
    public void ui() throws Exception{

        //Espresso.onView(withId(R.id.test_tv_test)).check(matches(isDisplayed()));
        Espresso.onView(withId(R.id.test_btn_test)).perform(click());
        Espresso.onView(withId(R.id.test_tv_test)).check(matches(withText("hello Stone")));

    }

    @Test
    public void test() {
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        try {
            Student student = new Student();
            student.setAge(20);
            student.setName("Stone");
            jsonArray.put(jsonObject);
           int a;
            System.out.println("s");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Test
    public void Timer() {

    }
}
